<!--
- Author:   .
- Date:    2018/1/19 0019.
- File:    积分转经验值.
-->
<template>
  <div>
    <div class="Withdrawals">
      <p class="pl20" style="line-height: 35px;" v-if="integralType == '2'">当前可用积分: <span>{{memberInfo.freeze_balance}}</span>
      </p>
      <p class="pl20" style="line-height: 35px;" v-if="integralType == '3'">当前可用股权积分: <span>{{memberInfo.stock}}</span>
        <span>, 可转出：{{stockTransferMax | toFixed(2)}}</span></p>
      <ul>
        <li v-if="integralType == '2'">
          <label><span class="nim">转出积分</span><input type="number" placeholder="请输入转出积分数" v-model="amount"></label></li>
        <li v-if="integralType == '3'">
          <label><span class="nim">转出股权</span><input type="number" placeholder="请输入转出股权数" v-model="amount"></label></li>
      </ul>
    </div>
    <p style="padding-left: 10px;padding-top: 10px;" v-if="integralType == '2'">每日可申请多次积分转经验值，在系统未审核前可撤消重新申请 <br/>经验值转出金额100%到账，到账时间为申请后第七天10：00 <br/>到账的经验值可购买商品
    </p>
    <p style="padding-left: 10px;padding-top: 10px;" v-if="integralType == '3'">仅限每年2月的最后一天转出，转出比例为15%，在系统未审核前可撤消重新申请<br>转出至经验值为1：1到账，到账时间为申请后第七天10：00<br>到账的经验值可购买商品
    </p>
    <div class="pl20 pr20 mt35">
      <a class="but_1 wauto disb tc" @click="confirmPwd">提交</a>
    </div>
    <footer-tab></footer-tab>
  </div>
</template>

<script>
  import {mapModules, mapRules} from 'vuet'
  import payPwd from '../../../components/payPwd'
  export default{
    mixins: [
      mapModules({memberInfo: 'memberInfo'}),
      mapRules({need: ['memberInfo']})
    ],
    data() {
      return {
        integralType: this.$route.query.type, // 2 积分 3 股权积分
        amount: ''
      }
    },
    components: {},
    computed: {
      stockTransferMax: function () {
        if (this.memberInfo.stock) {
          return this.memberInfo.stock * 0.15
        }
        return 0
      }
    },
    watch: {
      amount: function (newValue) {
        if (newValue == '') {
          return
        }
        let maxMoney = 0
        if (this.integralType == '2') {
          maxMoney = this.memberInfo.freeze_balance
        } else if (this.integralType == '3') {
          maxMoney = this.stockTransferMax
        }
        if (parseFloat(newValue) > parseFloat(maxMoney)) {
          this.$toast('超出了最大可用积分')
          this.amount = maxMoney.toFixed(2)
        }
      }
    },
    methods: {
      confirmPwd() {
        if (!this.amount || parseFloat(this.amount) <= 0) {
          this.$toast('请输入正确的积分数')
          return
        }
        payPwd({}, this.transfer)
      },
      transfer() {
        this.$request.integral2balance(this.amount, this.integralType).then(data => {
          this.$toast('提交成功')
          this.$router.push({name: 'account-index'})
        }).catch(e => {
          this.$toast('提交失败:' + e.msg)
          console.error('积分转经验值失败', e)
        })
      }
    }
  }
</script>

<style>

</style>